package recordsDatabase;




import java.util.ArrayList;


public class ListOfPersons  {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4655478063173246076L;

	// create the list
	private ArrayList<Person> personsList;
	
	private static volatile ListOfPersons instance;

	// This method is called getInstance. It uses a double - locking mechanism
	// to ensure
	// synchronization between threads when accessed so that no more than one
	// instance is created.
	// Finally the instance of the single List of records is returned.

	public static ListOfPersons getInstance() {
		if (instance == null) {
			synchronized (ListOfPersons.class) {
				if (instance == null)
					instance = new ListOfPersons();
			}
		}
		return instance;
	}
	
	public ListOfPersons(){
		personsList = new ArrayList<Person>(); 
	}
	
	public ArrayList<Person> getPersonsList(){
		return personsList;
	}
	
	public void addPerson(Person p){
		personsList.add(p);
		personsList.trimToSize();
	}
	public void reset(){
		personsList.clear();
	}
	
	
	
	public int	getLength(){
		return personsList.size();
	}
	
	public Person getPerson(String person){
		Person tmpPerson = null;
			for (Person p: personsList){
				if (p.getRecord("Name").getCategoryDetailsList().get(0).getField().contains(person)){
					return p;
				}
			} 
		return tmpPerson;
	}
}
